---------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Conditional/Primary/PredictedValues.log
  log type:  text
 opened on:  12 Nov 2016, 21:31:56

. cd "/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Conditional/Primary";
/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Conditional/Primary

. **************************************************************;
. *Author: Jeff Carter                                         *;
. *Date: Wednesday, December 3, 2014                              *;
. *Purpose: Simulating Predictions                *;
. **************************************************************;
. *********************************;
. **      Peace to War            *;
. *********************************;
. use "/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Conditional/Primary/SimData.dta";

. postutil clear;

. postfile mypost prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 diff_hat0 diff_lo0 diff_hi0
>                 prob_hat01 lo01 hi01 prob_hat11 lo11 hi11 diff_hat01 diff_lo01 diff_hi01
>                 delta_hat delta_lo delta_hi using PredictedValues, replace;
(note: file PredictedValues.dta not found)

. noisily display "start";
start

. local a=0 ;

. while `a' < 4 { ;
  2. {;
  3. *termlimited milservice termlimited_mil  parliament civwar  rgdp96pc_gle  growth_gle;
. *majpow numbord mm time_mid time2_mid time_3mid;
.  scalar h_Accountable =   0  ;
  4. scalar h_LameDuck= 1  ;
  5. scalar h_Civilian = 0;
  6. scalar h_Military = 1;
  7. scalar h_Constant = 1;
  8. scalar h_Parliament = 0;
  9. scalar h_CivilWar = 0;
 10. scalar h_GDPpc =  12589.35;
 11. scalar h_Growth = 3.453132;
 12. scalar h_MajorPower = 0;
 13. scalar h_Borders = 2;
 14. scalar h_Mobilization =  -.0008714 ;
 15. scalar h_Time = 5;
 16.  scalar h_Female =0 ;
 17.  scalar h_Rivalry = 0 ;
 18.  scalar h_Hawkish = 0;
 19. generate x_betahat0 = MG_b1*h_Accountable
>     + MG_b2*(`a')
>     + MG_b3*(h_Accountable*`a')
>     + MG_b4*h_Rivalry
>     + MG_b5*h_Borders
>     + MG_b6*h_Parliament
>     + MG_b7*h_Female 
>     + MG_b8*h_Time 
>     + MG_b9*(h_Time^2)
>     + MG_b10*(h_Time^3)
>     + MG_b11*h_Constant;
 20. generate x_betahat1 = MG_b1* h_LameDuck
>     + MG_b2*`a'
>     + MG_b3*(h_LameDuck*`a')
>     + MG_b4*h_Rivalry
>     + MG_b5*h_Borders
>     + MG_b6*h_Parliament
>     + MG_b7*h_Female 
>     + MG_b8*h_Time 
>     + MG_b9*(h_Time^2)
>     + MG_b10*(h_Time^3)
>     + MG_b11*h_Constant;
 21.  gen prob0=1/(1+exp(-x_betahat0));
 22. gen prob1=1/(1+exp(-x_betahat1));
 23.  gen diff0=prob1-prob0 ;
 24. egen probhat0=mean(prob0) ;
 25. egen probhat1=mean(prob1) ;
 26. egen diffhat0=mean(diff0) ;
 27. generate x_betahat01 =   MG_b1*h_Accountable
>     + MG_b2*`a'
>     + MG_b3*(h_Accountable*`a')
>     + MG_b4*h_Rivalry
>     + MG_b5*h_Borders
>     + MG_b6*h_Parliament
>     + MG_b7*h_Female 
>     + MG_b8*h_Time 
>     + MG_b9*(h_Time^2)
>     + MG_b10*(h_Time^3)
>     + MG_b11*h_Constant;
 28.  generate x_betahat11 =   MG_b1* h_LameDuck
>     + MG_b2*`a'
>     + MG_b3*(h_LameDuck*`a')
>     + MG_b4*h_Rivalry
>     + MG_b5*h_Borders
>     + MG_b6*h_Parliament
>     + MG_b7*h_Female 
>     + MG_b8*h_Time 
>     + MG_b9*(h_Time^2)
>     + MG_b10*(h_Time^3)
>     + MG_b11*h_Constant;
 29.   gen prob01=1/(1+exp(-x_betahat01));
 30. gen prob11=1/(1+exp(-x_betahat11));
 31. gen diff01=prob11-prob01 ;
 32. egen probhat01=mean(prob01) ;
 33. egen probhat11=mean(prob11) ;
 34. egen diffhat01=mean(diff01) ;
 35. gen delta=diff01-diff0;
 36. egen deltahat=mean(delta);
 37. tempname prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 diff_hat0 diff_lo0 diff_hi0
>          prob_hat01 lo01 hi01 prob_hat11 lo11 hi11 diff_hat01 diff_lo01 diff_hi01
>          delta_hat delta_lo delta_hi;
 38.     _pctile prob0, p(2.5,97.5) ;
 39.     scalar `lo0'=r(r1) ;
 40.     scalar `hi0'=r(r2) ;
 41.     _pctile prob1, p(2.5,97.5) ;
 42.     scalar `lo1'=r(r1) ;
 43.     scalar `hi1'=r(r2) ;
 44.     _pctile diff0, p(2.5,97.5) ;
 45.     scalar `diff_lo0'= r(r1) ;
 46.     scalar `diff_hi0'=r(r2) ;
 47.     scalar `prob_hat0'=probhat0 ;
 48.     scalar `prob_hat1'=probhat1 ;
 49.     scalar `diff_hat0'=diffhat0 ;
 50.        _pctile prob01, p(2.5,97.5) ;
 51.     scalar `lo01'=r(r1) ;
 52.     scalar `hi01'=r(r2) ;
 53.     _pctile prob11, p(2.5,97.5) ;
 54.     scalar `lo11'=r(r1) ;
 55.     scalar `hi11'=r(r2) ;
 56.     _pctile diff01, p(2.5,97.5) ;
 57.     scalar `diff_lo01'= r(r1) ;
 58.     scalar `diff_hi01'=r(r2) ;
 59.     scalar `prob_hat01'=probhat01 ;
 60.     scalar `prob_hat11'=probhat11 ;
 61.     scalar `diff_hat01'=diffhat01 ;
 62.     _pctile delta, p(2.5,97.5) ;
 63.     scalar `delta_lo'= r(r1) ;
 64.     scalar `delta_hi'=r(r2) ;
 65.     scalar `delta_hat'=deltahat;
 66.     post mypost (`prob_hat0') (`lo0') (`hi0') (`prob_hat1') (`lo1') (`hi1') (`diff_hat0') (`diff_lo0') (`diff_hi0')
>                 (`prob_hat01') (`lo01') (`hi01') (`prob_hat11') (`lo11') (`hi11') (`diff_hat01') (`diff_lo01') (`diff_hi0
> 1')
>                 (`delta_hat') (`delta_lo') (`delta_hi')
> 
>     ;
 67.     } ;
 68.     drop    x_betahat0 x_betahat1 prob0 prob1 diff0 probhat0 probhat1 diffhat0
>             x_betahat01 x_betahat11 prob01 prob11 diff01 probhat01 probhat11 diffhat01
>             delta deltahat;
 69.     local a=`a'+ 1 ;
 70.     display "." _c ;
 71.     } ;
....
. display "" ;


.  postclose mypost ;

. use PredictedValues, clear;

. gen ruler = _n;

. sum;

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
   prob_hat0 |         4    .0732617    .0227611   .0491939   .1018392
         lo0 |         4    .0455879    .0097472    .033005   .0554421
         hi0 |         4    .1113332    .0437767   .0705791   .1698744
   prob_hat1 |         4    .0338242    .0059647   .0281312   .0417253
         lo1 |         4    .0141887    .0039165   .0091214    .017303
-------------+--------------------------------------------------------
         hi1 |         4    .0722902    .0351547   .0430756     .12064
   diff_hat0 |         4   -.0394375    .0168374  -.0601139  -.0210627
    diff_lo0 |         4   -.0800121    .0423493  -.1364681  -.0407553
    diff_hi0 |         4    .0023921    .0152221  -.0105701   .0243504
  prob_hat01 |         4    .0732617    .0227611   .0491939   .1018392
-------------+--------------------------------------------------------
        lo01 |         4    .0455879    .0097472    .033005   .0554421
        hi01 |         4    .1113332    .0437767   .0705791   .1698744
  prob_hat11 |         4    .0338242    .0059647   .0281312   .0417253
        lo11 |         4    .0141887    .0039165   .0091214    .017303
        hi11 |         4    .0722902    .0351547   .0430756     .12064
-------------+--------------------------------------------------------
  diff_hat01 |         4   -.0394375    .0168374  -.0601139  -.0210627
   diff_lo01 |         4   -.0800121    .0423493  -.1364681  -.0407553
   diff_hi01 |         4    .0023921    .0152221  -.0105701   .0243504
   delta_hat |         4           0           0          0          0
    delta_lo |         4           0           0          0          0
-------------+--------------------------------------------------------
    delta_hi |         4           0           0          0          0
       ruler |         4         2.5    1.290994          1          4

. saveold PredictedValues, replace;
file PredictedValues.dta saved

. log close;
      name:  <unnamed>
       log:  /Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Conditional/Primary/PredictedValues.log
  log type:  text
 closed on:  12 Nov 2016, 21:31:56
---------------------------------------------------------------------------------------------------------------------------
